package com.example.service;

import com.example.entity.Account;
import com.example.entity.Collect;
import com.example.mapper.CollectMapper;
import com.example.utils.TokenUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CollectService {
    @Resource
    private CollectMapper collectMapper;

    public void set(Collect collect){
        Account currentUser = TokenUtils.getCurrentUser();
        collect.setUser_id(currentUser.getId());
        Collect dblCollect = collectMapper.selectUserCollect(collect);
        if(dblCollect == null){
            //没有点赞就给它点赞
            collectMapper.insert(collect);
        }else{
            collectMapper.deleteById(dblCollect.getId());
        }
    }

    public Collect selectUserCollect(Integer fid, String module){
        Account currentUser = TokenUtils.getCurrentUser();
        Collect collect = new Collect();
        collect.setUser_id(currentUser.getId());
        collect.setFid(fid);
        collect.setModule(module);
        return collectMapper.selectUserCollect(collect);
    }

    public int selectByFidAndModule(Integer fid, String module){
        return collectMapper.selectByFidAndModule(fid,module);
    }



}
